
<h1><span class="yiyi-st" id="yiyi-13">numpy.core.defchararray.chararray.item</span></h1>
        <blockquote>
        <p>原文：<a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.core.defchararray.chararray.item.html">https://docs.scipy.org/doc/numpy/reference/generated/numpy.core.defchararray.chararray.item.html</a></p>
        <p>译者：<a href="https://github.com/wizardforcel">飞龙</a> <a href="http://usyiyi.cn/">UsyiyiCN</a></p>
        <p>校对：（虚位以待）</p>
        </blockquote>
    
<dl class="method">
<dt id="numpy.core.defchararray.chararray.item"><span class="yiyi-st" id="yiyi-14"> <code class="descclassname">chararray.</code><code class="descname">item</code><span class="sig-paren">(</span><em>*args</em><span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-15">将数组的元素复制到标准Python标量并返回。</span></p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name">
<col class="field-body">
<tbody valign="top">
<tr class="field-odd field"><th class="field-name"><span class="yiyi-st" id="yiyi-16">参数：</span></th><td class="field-body"><p class="first"><span class="yiyi-st" id="yiyi-17"><strong>* args</strong>：参数（变量号和类型）</span></p>
<blockquote>
<div><ul class="simple">
<li><span class="yiyi-st" id="yiyi-18">none：在这种情况下，该方法仅适用于具有一个元素（<em class="xref py py-obj">a.size == 1</em>）的数组，该元素将复制到标准Python标量对象中并返回。</span></li>
<li><span class="yiyi-st" id="yiyi-19">int_type：该参数被解释为数组的平面索引，指定要复制和返回的元素。</span></li>
<li><span class="yiyi-st" id="yiyi-20">int_types的元组：函数与单个int_type参数一样，只是参数被解释为数组中的nd-index。</span></li>
</ul>
</div></blockquote>
</td>
</tr>
<tr class="field-even field"><th class="field-name"><span class="yiyi-st" id="yiyi-21">返回：</span></th><td class="field-body"><p class="first"><span class="yiyi-st" id="yiyi-22"><strong>z</strong>：标准Python标量对象</span></p>
<blockquote class="last">
<div><p><span class="yiyi-st" id="yiyi-23">数组的指定元素的副本作为适当的Python标量</span></p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<p class="rubric"><span class="yiyi-st" id="yiyi-24">笔记</span></p>
<p><span class="yiyi-st" id="yiyi-25">当<em class="xref py py-obj">a</em>的数据类型为longdouble或clongdouble时，item()返回标量数组对象，因为没有可用的Python标量不会丢失信息。</span><span class="yiyi-st" id="yiyi-26">Void数组返回item()的缓冲区对象，除非定义了字段，在这种情况下返回一个元组。</span></p>
<p><span class="yiyi-st" id="yiyi-27"><a class="reference internal" href="#numpy.core.defchararray.chararray.item" title="numpy.core.defchararray.chararray.item"><code class="xref py py-obj docutils literal"><span class="pre">item</span></code></a>与[args]非常相似，除了返回一个标准的Python标量，而不是一个数组标量。</span><span class="yiyi-st" id="yiyi-28">这对于加速访问数组的元素和使用Python的优化数学对数组的元素进行算术非常有用。</span></p>
<p class="rubric"><span class="yiyi-st" id="yiyi-29">例子</span></p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">randint</span><span class="p">(</span><span class="mi">9</span><span class="p">,</span> <span class="n">size</span><span class="o">=</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">3</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span>
<span class="go">array([[3, 1, 7],</span>
<span class="go">       [2, 8, 3],</span>
<span class="go">       [8, 5, 3]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span><span class="o">.</span><span class="n">item</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span>
<span class="go">2</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span><span class="o">.</span><span class="n">item</span><span class="p">(</span><span class="mi">7</span><span class="p">)</span>
<span class="go">5</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span><span class="o">.</span><span class="n">item</span><span class="p">((</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">))</span>
<span class="go">1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span><span class="o">.</span><span class="n">item</span><span class="p">((</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">))</span>
<span class="go">3</span>
</pre></div>
</div>
</dd></dl>
